

export default {
    formatRichText (html) { //控制小程序中图片大小
        if (!html) {
            return '暂无商品详情'
        }
        let newContent = html.replace(/style=""/gi, '');
        // newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
        //     match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
        //     match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
        //     match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        //     return match;
        // });
        // newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
        //     match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
        //     return match;
        // });
        newContent = newContent.replace(/<br[^>]*\/>/gi, '');
        newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:0 auto;"');
        return newContent;
    },
    formatPhone (value, type) {
        if (type) {
            return value ? value.substring(0,3) + '****' + value.substring(7) : '';
        }
        return value ? value.substring(0,3) + ' **** ' + value.substring(7) : '';
    },
    formatAmount(s, divisor = 100) {
        var money = parseFloat(s);
        if (money) {
            s = (money / divisor).toFixed(2) + "";
            var l = s.split(".")[0].split("").reverse();
            var r = s.split(".")[1];
            var t = "";
            l.forEach(function (ll, key) {
                t += l[key] + ((key + 1) % 3 == 0 && (key + 1) != l.length ? "," : "");
            });
            return t.split("").reverse().join("") + "." + r;
        } else if (s == 0) {
            return "0.00"
        } else {
            return '---';
        }
    },

}
